const {
    add,
    del,
    edit,
    search,
    searchBy,
} = require('../js/mysql.js')

const router = require('koa-router')()
const { dateFormat } = require('@jiess/utils')
const jwtAuth = require('../jwtAuth')

router.use(jwtAuth)

router.prefix('/home')

// 查询已发布、进行中、已完结的数据
router.get('/check', async (ctx, next) => {
    let data1 = await searchBy(`train_state=1`, 'train');
    let data2 = await searchBy(`train_state=3`, 'train');
    let data3 = await searchBy(`train_state=5`, 'train');
    ctx.body = {
        code: 200,
        msg: '操作成功',
        data: {
            published: data1.length,
            inProgress: data2.length,
            finished: data3.length,
        }
    }
})
// 查询近一周的每日培训数量
router.get('/week', async (ctx, next) => {
    const {id} = ctx.request.query;
    let sql = `order by id DESC LIMIT ${id}-1,7`;
    let data = await searchBy(sql, 'progress');
    ctx.body={
        code:200,
        msg:'操作成功',
        data
    }
})
// 

module.exports = router